package org.karelun.gef.figure;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;

public class PackageFigure extends NodeFigure {
	private class PackageShap extends Shape {

		public PackageShap() {
		}

		protected void fillShape(Graphics graphics) {
			Rectangle r = getBounds();
			Rectangle rect = new Rectangle(r.x, r.y, r.width / 4, r.height / 4);
			Rectangle rect1 = new Rectangle(r.x, r.y + r.height / 4,
					r.width - 1, r.height * 3 / 4 - 1);
			Color color = new Color(Display.getCurrent(), 255, 255, 206);

			// graphics.setLineStyle(SWT.LINE_DASHDOT);
			// graphics.setAlpha(10);
			// graphics.rotate(3);
			graphics.setBackgroundColor(color);
			graphics.fillRectangle(rect);
			graphics.drawRectangle(rect);
			graphics.fillRectangle(rect1);
			graphics.drawRectangle(rect1);

		}

		protected void outlineShape(Graphics graphics) {
		}
	}

	private PackageShap shape;

	public PackageFigure() {
		super();
		BorderLayout layout = new BorderLayout();
		setLayoutManager(layout);
		shape = new PackageShap();
		label = new Label();
		shape.add(label);
		add(shape, BorderLayout.CENTER);
		setOpaque(true);
	}

	public void setBounds(Rectangle rect) {
		super.setBounds(rect);
		label.setBounds(rect);
	}

	@Override
	protected void setBGColor(Color color) {
		if (shape == null)
			return;
		shape.setBackgroundColor(color);
		repaint();
	}
}
